#pragma once
#include"AbstractLayer.h"
#include<string>

class DemoRayCast : public AbstractLayer,public b2RayCastCallback
{
public:
	createScene(DemoRayCast)
	CREATE_FUNC(DemoRayCast)
		
	bool init();

	void box2DAppReady() override;

	void createBody();

	void update(float dt) override;

	void moveRay();
	
	void onKeyPressed(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event * event) override;

	void onKeyReleased(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event * event)override;

	virtual float32 ReportFixture(b2Fixture* fixture, const b2Vec2& point,const b2Vec2& normal, float32 fraction);

	void draw(cocos2d::Renderer *renderer, const cocos2d::Mat4& transform, uint32_t flags) override;

	void movePlayer();
private:
	const std::string USER_DATA_PLAYER = "player";
	const std::string USER_DATA_GROUND = "ground";
	const std::string USER_DATA_PLATFROM = "platfrom";

	b2Body* player;
	float m_speed = 50 * 0.03125;
	bool isMove = false;
	b2Vec2 point1, point2;
	float rayLength = 300 * 0.03125;
	float rayAngle = 3.14*0.5;
	const float ANGLE_MAX = 3.14 * 8 / 9;
	const float ANGLE_MIN = 3.14 / 9;
	float angle_speed = 3.14 / 200;
	
	b2Vec2 closetPoint;
	b2Body* closetBody;
	b2Color red = b2Color(1, 0, 0);
	bool isCircle;
	float cradius = 15 * 0.03125;
	b2Vec2 cpos;
};